package liuh.com.ledlamp.popup;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;

import liuh.com.ledlamp.R;
import liuh.com.ledlamp.adapter.NormalRecyclerViewAdapter;
import razerdp.basepopup.BasePopupWindow;

/**
 * @author :liuh
 * @note
 * @date: 2016-12-01
 */
public class ScalePopup extends BasePopupWindow implements View.OnClickListener{

    private View popupView;
    Activity context_act;
    //
    NormalRecyclerViewAdapter mRecyclerViewAdapter;
    int position;

    public ScalePopup(Activity context,NormalRecyclerViewAdapter mRecyclerViewAdapter,int position) {
        super(context);
        context_act=context;
        this.mRecyclerViewAdapter=mRecyclerViewAdapter;
        this.position=position;
        bindEvent();
    }



    @Override
    protected Animation initShowAnimation() {
        return getDefaultScaleAnimation();
    }


    @Override
    public View getClickToDismissView() {
        return popupView.findViewById(R.id.click_to_dismiss);
    }

    @Override
    public View onCreatePopupView() {
        popupView= LayoutInflater.from(getContext()).inflate(R.layout.popup_normal,null);
        return popupView;
    }

    @Override
    public View initAnimaView() {
        return popupView.findViewById(R.id.popup_anima);
    }

    private void bindEvent() {
        if (popupView!=null){
            popupView.findViewById(R.id.upd_tx).setOnClickListener(this);
            popupView.findViewById(R.id.del_tx).setOnClickListener(this);
        }

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.upd_tx:
                this.dismiss();
                InputPopup input_popup= new InputPopup((Activity) getContext(),mRecyclerViewAdapter,position);
                input_popup.showPopupWindow();
                /*InputDialog input_dialog= new InputDialog(getContext(),mRecyclerViewAdapter,position);
                input_dialog.showInputDialog();*/
                break;
            case R.id.del_tx:
                mRecyclerViewAdapter.remove(position);
                this.dismiss();
                break;
        }

    }
}
